<template>
  <div class="loan-amount-card">
    <a-modal
      :title="loanModal.title"
      :visible="loanModal.visible"
      :mask-closable="false"
      :keyboard="false"
      :closable="false"
    >
      <template #closeIcon />
      <div class="loading-container">
        <a-icon
          type="loading"
          class="loading-icon"
        />

        <span class="text">Debit limit calculation in progress...</span>
      </div>
      <template #footer />
    </a-modal>

    <div class="money-text">
      <span class="symbol">$</span>
      <countTo
        :start-val="0"
        :end-val="Number(moneyState.amount)"
        :duration="3000"
      />
    </div>
    <div class="loan-container">
      <div class="available-container">
        <div class="available">
          Available
        </div>
        <div class="fees">
          {{ moneyState.stage }} days term with {{ moneyState.cost.connect }} fees
        </div>
      </div>

      <!-- shape="round" -->
      <!-- :disabled="!authentication" -->
      <a-button
        class="loan-button ant-btn-default"
        :loading="loading"
        :disabled="loanDisabled"
        @click="loan"
      >
        <!--  -->
        Loan
      </a-button>
    </div>
  </div>
</template>

<script>
import form from './form';
import actions from './actions';
import { mapGetters } from 'vuex';
import modal from './modal';
import loan from './loan';
import countTo from 'vue-count-to';

export default {
  components: {
    countTo
  },

  mixins: [form, actions, modal, loan],

  computed: {
    ...mapGetters(['currentUser', 'authentication'])
  }
};
</script>

<style lang="scss" scoped>
.loading-container {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  .loading-icon {
    text-align: center;
    color: $theme-color;
    font-size: 60px;
  }
  .text {
    font-size: $font-size-lg;
    margin-top: $margin-lg;
    font-weight: bold;
  }
}

.loan-amount-card {
  padding: 30px;
  height: 213px;
  background: $theme-color;
  box-shadow: 0px 0px 6px 4px rgba(236, 236, 236, 0.5);
  border-radius: $border-radius-lg;
  border: 1px solid $gray-18;
  color: $white;
  display: flex;
  flex-direction: column;
  justify-content: space-between;

  .money-text {
    font-size: 72px;
    color: $white;
    // margin-bottom: $margin-xs;
    line-height: 92px;

    .symbol {
      color: $yellow-1;
    }
  }
  .loan-container {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    .available-container {
      .available {
        font-size: $font-size-lg;
      }
    }
  }
}

@media (max-width: $screen-md) {
  .loan-amount-card {
    padding: $padding-sm;
  }
}
</style>

<style lang="scss">
.loan-button {
  font-size: $font-size-lg;
  width: 144px;
  height: 32px;
  line-height: 32px;
  text-align: center;
  background: #FFFFFF;
  border-radius: 5px;
  color: $theme-color;
  font-weight: bold;
}
</style>
